import com.beans.UserBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import java.security.cert.X509Certificate;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-08-10
 * Time:13:49
 */
public class App {
    public static void main(String[] args) {
        System.out.println("你好！");
        // 1.得到spring上下文对象
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");
        // 2.根据上下文对象提供的方法获取到bean
        UserBean userBean = (UserBean) context.getBean("user");
        UserBean userBean1 = context.getBean(UserBean.class);
        UserBean userBean2 = context.getBean("user",UserBean.class);

        // 3.使用bean
        userBean.sayHi("张三");

//        // 1.得到bean工厂
//        BeanFactory factory = new XmlBeanFactory(
//                new ClassPathResource("spring-config.xml")
//        );
//        // 2.获取bean
//        UserBean userBean = (UserBean) factory.getBean("user");
//        // 3.使用bean
//        userBean.sayHi("李四");

    }
}
